package com.adroiti.texasholdem.engine.combinations;

import java.util.ArrayList;
import java.util.List;

import com.adroiti.texasholdem.Card;

public class FullHouse extends AbstractCombination {

	
	
	private Pair pairComb;
	private ThreeOfKind threeComb;

	public FullHouse(){
		this(new Pair(), new ThreeOfKind());
	}
	
	public FullHouse(Pair pairComb, ThreeOfKind threeComb){
		this.pairComb = pairComb;
		this.threeComb = threeComb;
	}
	
	
	@Override
	public int getRank(List<Card> player, List<Card> table) {
		
		List<Card> cards = new ArrayList<Card>(player);
		cards.addAll(table);
		
		
		int three = threeComb.getRank(player, table);
		if(three == 0){
			return 0;
		}
		for(int i = 0; i < cards.size(); i++){
			if(cards.get(i).getRank() == three){
				cards.remove(i);
				i--;
			}
		}
		
		int pair = pairComb.getRank(cards, new ArrayList<Card>());
		
		if( three > 0 && pair > 0 && three != pair){
			return three * 10 + pair;
		}
		
		return 0;
	}

	@Override
	public String getName() {
		return "Full house";
	}

	@Override
	public int getCombinationRank() {
		return 7;
	}

}
